#include "SocketClient.h"

#include "QueueMananger.h"

SocketClient::SocketClient( QHostAddress host, qint16 port ) :
    QObject( 0 )
{
    socket = new QUdpSocket( this );
    this->host = host;
    this->port = port;
}

SocketClient::~SocketClient()
{
    if ( socket )
    {
        delete socket;
    }
}

void SocketClient::send()
{
    while( true )
    {
        QByteArray message( QueueMananger::get()->popRequest() );

        if ( !message.isEmpty() )
        {
            socket->writeDatagram( message, host, port );
        }
        else
        {
            break;
        }
    }
}






